<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<base href="<%=basePath%>"/>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>合同商品管理列表</title>
		<link rel="stylesheet" href="res/layui/css/layui.css">
		<script src="res/js/jquery-2.1.4.min.js" type="text/javascript" ></script>
		<script src="res/layui/layui.js"></script>
	</head>
	<body>
	<div style="padding-top: 10px;margin-bottom: -10px;">
		合同名称：
		<div class="layui-inline" style="width: 140px;">
			<input class="layui-input" name="pactTitle" id="pactTitle"
				autocomplete="off">
		</div>
		合同编号：
		<div class="layui-inline" style="width: 140px;">
			<input class="layui-input" name="pactNumber" id="pactNumber"
				autocomplete="off">
		</div>
		
		<button class="layui-btn" data-type="reload" onclick="reloadData()">搜索</button>
		<button data-type="auto" class="layui-btn layui-btn-normal"
			onclick="showAddOrUpdate()">新增合同商品列表</button>
		<button data-type="auto" class="layui-btn layui-btn-normal"
			onclick="showAddOrUpdatepl()">新增合同配料列表</button>
	</div>
	<table class="layui-table" id="Pacte" lay-filter="demoo"></table> 
	
	
	<script type="text/javascript">
		var table;

		var loadIndex;

		var openIndex;
		//合同商品表
		function showAddOrUpdate(pactId) {
			var url;
			if (pactId != null) {
				url = "pages/Pact.jsp?pactId=" + pactId;
			} else {
				url = "pages/PactAdd.jsp";
			}
			openIndex = layer.open({
				type : 2//样式
				,
				skin : 'layui-layer-molv'//样式
				,
				area : [ '85%', '70%' ],
				title : "合同维护"//标题
				,
				id : 'mesFrom' //防止重复弹出
				,
				content : url,
				shade : [ 0.8, '#393D49' ] //显示遮罩
				,
				shadeClose : true//点击也能遮罩层关闭
				,
				anim : 2
			//弹出动画 
			});
		}
		
		//合同配料表
		function showAddOrUpdatepl(pactId) {
			var url;
			if (pactId != null) {
				url = "pages/Pact.jsp?pactId=" + pactId;
			} else {
				url = "pages/Pactdosing.jsp";
			}
			openIndex = layer.open({
				type : 2//样式
				,
				skin : 'layui-layer-molv'//样式
				,
				area : [ '85%', '70%' ],
				title : "合同维护"//标题
				,
				id : 'mesFrom' //防止重复弹出
				,
				content : url,
				shade : [ 0.8, '#393D49' ] //显示遮罩
				,
				shadeClose : true//点击也能遮罩层关闭
				,
				anim : 2
			//弹出动画 
			});
		}

		

		function deleteRec(pactId, i) {
			var url = "Pact/delete.action";
			$.post(url, {
				"pactId" : pactId
			}, function(info) {
				layer.msg(info.mes);
				layer.close(i);
			});
		}

		layui.use([ 'table' ], function() {   

			table = layui.table;
			loadIndex = layer.load();
			//方法级渲染
			table.render({
				loading : true,
				id : 'pactId',
				page : true,
				height : 383,
				size : "sm",
				elem : '#Pacte',
				url : 'Pact/listPact.action',
				method : 'post',
				where : {

				},
				cols : [ [ {
					field : 'PACT_TITLE',
					title : '合同名称',
					width : 110,
					align : 'center',
					sort : true
				}, {
					field : 'PACT_NUMBER',
					title : '合同编号',
					width : 150,
					align : 'center',
					sort : true
				}, {
					field : 'APPLY_NAME',
					title : '供货商名称',
					width : 150,
					align : 'center',
					sort : true
				}, {
					field : 'PACT_SIGNTIME',
					title : '签订合同的时间',
					width : 150,
					align : 'center',
					sort : true
				}, {
					field : 'PARTB_NAME',
					title : '合同内容',
					width : 110,
					align : 'center',
					sort : true
				}, {
					field : 'PACT_TEXT',
					title : '甲方名字',
					width : 110,
					align : 'center',
					sort : true
				}, {
					field : 'PARTA_NAME',
					title : '乙方名字',
					width : 110,
					align : 'center',
					sort : true
				}, {
					field : 'PACT_ENDTIME',
					title : '有效期',
					width : 100,
					align : 'center',
					sort : true
				} ] ]

				,
				done : function(res, curr, count) {
					layer.close(loadIndex);//加载层关闭  
				}
			});

			//监听工具条
			table.on('tool(demoo)', function(obj) {
				var data = obj.data;
				if (obj.event === 'del') {
					layer.confirm('真的删除行么', function(index) {
						var i = layer.load();
						deleteRec(data.pactId, i);
						obj.del();
						layer.close(index);
					});
				} else if (obj.event === 'edit') {
					showAddOrUpdate(data.pactId);
				}
			});

			$('.demoTable .layui-btn').on('click', function() {
				var type = $(this).data('type');
				active[type] ? active[type].call(this) : '';
			});
		});
		
		function reloadData(){
			table.reload('pactId', {
				where : {
					'pactTitle' : $("#pactTitle").val(),
					'pactNumber' : $("#pactNumber").val(),
				}
			});
		}
		
	</script>

</body>
</html>